class FunctionResult:
    """表示待检测函数的一个匹配候选结果的实体类。

       该类封装了候选函数的匹配结果信息、匹配方法及多种相似度指标，
       用于在TPL识别和TPL Version识别场景中传递结果。

       Attributes:
           arkts_id: 待检测的arkts函数id
           arkts_library：待检测的arkts的库名称
           npm_library：匹配到函数所属的npm的库名称
           npm_version：匹配到函数所属的npm的版本
           npm_id (str): 候选的唯一 ID 字符串。
           npm_name (str): 候选函数的可读名称。
           match_method (str): 使用的匹配方法名称。
           vector_similarity (float): 向量相似度得分，范围 [0, 1]。
           isomorphic_ratio (float): 同构比例，表示AST结构相似程度。
           diff_similarity (float): 异构语义相似度，基于代码差异计算。
           distance (float): 距离度量（欧氏距离），值越小越相似。
           processing_time：匹配所用时间
       """
    def __init__(
        self,
        arkts_id: str = "",
        arkts_library: str = "",
        arkts_version: str = "",
        npm_library: str = "",
        npm_id: str = "",
        npm_name: str = "",
        npm_version: str = "",
        match_method: str = "",
        vector_similarity: float = float('nan'),
        isomorphic_ratio: float = float('nan'),
        diff_similarity: float = float('nan'),
        distance: float = float('nan'),
        processing_time: float = float('nan'),
    ) -> None:
        # 字符串字段
        self.arkts_id = arkts_id
        self.arkts_library = arkts_library
        self.arkts_version = arkts_version
        self.npm_library = npm_library
        self.npm_id = npm_id
        self.npm_name = npm_name
        self.npm_version = npm_version
        self.match_method: str = match_method
        # 浮点数字段
        self.vector_similarity: float = vector_similarity
        self.isomorphic_ratio: float = isomorphic_ratio
        self.diff_similarity: float = diff_similarity
        self.distance: float = distance
        self.processing_time: float = processing_time

    def to_dict(self) -> dict:
        """将对象转换为字典格式，便于存储到 MongoDB 或序列化。

        Returns:
            dict: 包含所有属性的字典
        """
        return {
            'arkts_id': self.arkts_id,
            'arkts_library': self.arkts_library,
            'arkts_version': self.arkts_version,
            'npm_library': self.npm_library,
            'npm_id': self.npm_id,
            'npm_name': self.npm_name,
            'npm_version': self.npm_version,
            'match_method': self.match_method,
            'vector_similarity': self.vector_similarity,
            'isomorphic_ratio': self.isomorphic_ratio,
            'diff_similarity': self.diff_similarity,
            'distance': self.distance,
            'processing_time': self.processing_time
        }